import RobotError from "../errors/robot-error.js";
import HalfHpMedicine from "../item/half_hp_medicine.js";
import InvisibleMedicine from "../item/invisible _medicine.js";
import ReviveMedicine from "../item/revive_medicine.js";
import TenHpMedicine from "../item/ten_hp_medicine.js";
import Player from "../player/player.js";
import Goods from "./goods/goods.js";



export default class Shop {
	goodsMap: Map<string, Goods> = new Map();

	constructor() {
		let goods: Goods[] = [];
		//添加商品
		goods.push(new Goods(new ReviveMedicine(), 200));//还魂丹
		goods.push(new Goods(new HalfHpMedicine(), 1000));
		goods.push(new Goods(new TenHpMedicine(), 100));
		goods.push(new Goods(new InvisibleMedicine(), 500));


		for (let g of goods) {
			this.goodsMap.set(g.name, g);
		}
	}


	buy(client: Player, goodsName: string, num: number = 1) {
		if (!this.goodsMap.has(goodsName)) throw new RobotError("不存在该商品");
		return client.buy(this.goodsMap.get(goodsName), num);
	}

	getGoodsStr() {
		let goodsStr = "商品列表\n";
		for (let i of this.goodsMap) {
			goodsStr += "--------\n";
			goodsStr += "名称：" + i[0] + "\n";
			goodsStr += "价格：" + i[1].price + "\n";
			goodsStr += "介绍：" + i[1].intro + "\n";
		}
		goodsStr += "--------\n";
		return goodsStr;
	}
}

new Shop();